package com.mall.web.controller.goods.admin;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.core.page.TableDataInfo;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.goods.model.dto.GoodsCategoryDto;
import com.mall.goods.model.vo.GoodsCategoryVo;
import com.mall.goods.service.IGoodsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商城-商品分类Controller
 */
@RestController
@RequestMapping("/admin/goods/goodsCategory")
public class AdminGoodsCategoryController extends BaseController
{
    @Autowired
    private IGoodsCategoryService goodsCategoryService;

    /**
     * 查询商城-商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('goods:category:list')")
    @GetMapping("/list")
    public AjaxResult list(GoodsCategoryDto goodsCategoryDto)
    {
        List<GoodsCategoryVo> list = goodsCategoryService.selectGoodsCategoryList(goodsCategoryDto);
        return success(list);
    }

    /**
     * 导出商城-商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('goods:category:export')")
    @Log(title = "商城-商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsCategoryDto goodsCategoryDto)
    {
        List<GoodsCategoryVo> list = goodsCategoryService.selectGoodsCategoryList(goodsCategoryDto);
        ExcelUtil<GoodsCategoryVo> util = new ExcelUtil<GoodsCategoryVo>(GoodsCategoryVo.class);
        util.exportExcel(response, list, "商城-商品分类数据");
    }

    /**
     * 获取商城-商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodsCategoryService.selectGoodsCategoryById(id));
    }

    /**
     * 新增商城-商品分类
     */
    @PreAuthorize("@ss.hasPermi('goods:category:add')")
    @Log(title = "商城-商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsCategoryDto goodsCategoryDto)
    {
        return toAjax(goodsCategoryService.insertGoodsCategory(goodsCategoryDto));
    }

    /**
     * 修改商城-商品分类
     */
    @PreAuthorize("@ss.hasPermi('goods:category:edit')")
    @Log(title = "商城-商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsCategoryDto goodsCategoryDto)
    {
        return toAjax(goodsCategoryService.updateGoodsCategory(goodsCategoryDto));
    }

    /**
     * 删除商城-商品分类
     */
    @PreAuthorize("@ss.hasPermi('goods:category:remove')")
    @Log(title = "商城-商品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsCategoryService.deleteGoodsCategoryByIds(ids));
    }
}
